package example1;

import org.junit.Test;

import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;

public class CreateFileExample {

    @Test
    public void test() {
        String filePath = "C:/Users/yangyang/Desktop/dist.zip";
        long fileSizeInBytes = 249 * 1024; // 249KB

        try {
            // 创建文件对象
            File file = new File(filePath);

            // 使用RandomAccessFile创建文件
            RandomAccessFile raf = new RandomAccessFile(file, "rw");

            // 设置文件大小
            raf.setLength(fileSizeInBytes);

            System.out.println("文件创建成功！");
            System.out.println("文件路径: " + file.getAbsolutePath());
            System.out.println("文件大小: " + file.length() + " 字节");

            // 关闭RandomAccessFile
            raf.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
